#region

using System;
using System.Collections.Generic;
using System.Xml.Serialization;
using Diagnostics.Annotations;
using MobilePal.Collections;
using MobilePal.Rules;

#endregion

namespace MobilePal.State
{
    #region Imported Namespaces

    

    #endregion

    /// <summary>
    /// Describes and manipulates the application state.
    /// </summary>
    [UsedImplicitly(ImplicitUseFlags.IncludeMembers)]
    public sealed class ApplicationState
    {
        #region Constants and Fields

        [NotNull] private ActivityCollection _activities = new ActivityCollection();

        [NotNull] private ActivityCategoryCollection _categories = new ActivityCategoryCollection();

        [NotNull] private ActivityCategory _defaultCategory;

        [NotNull] private ActivityRuleCollection _rules = new ActivityRuleCollection();

        [NotNull] private ApplicationSettings _settings = new ApplicationSettings();

        #endregion

        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="ApplicationState"/> class.
        /// </summary>
        public ApplicationState()
        {
            _defaultCategory = new ActivityCategory(true, "Default");
            _categories.Add(_defaultCategory);
        }


        #endregion

        #region Properties

        /// <summary>
        /// Gets a collection of activities.
        /// </summary>
        /// <value>
        /// The collection of activities.
        /// </value>
        [NotNull]
        public ActivityCollection Activities
        {
            get { return _activities; }
            set { _activities = value; }

        }


        /// <summary>
        /// Gets a collection of categories.
        /// </summary>
        /// <value>
        /// A collection of categories.
        /// </value>
        [XmlArray("Categories")]
        [XmlArrayItem("Category")]
        [NotNull]
        public ActivityCategoryCollection Categories
        {
            get { return _categories; }
            set { _categories = value; }

        }


        /// <summary>
        /// Gets a collection of rules.
        /// </summary>
        /// <value>
        /// The collection of rules.
        /// </value>
        [XmlArray("Rules")]
        [XmlArrayItem("ToggleGroup", typeof (ToggleGroupRule))]
        [XmlArrayItem("ToggleReminder", typeof (ActivityToggleReminder))]
        [XmlArrayItem("DailyReminder", typeof (DailyActivityReminder))]
        [NotNull]
        public ActivityRuleCollection Rules
        {
            get { return _rules; }
            set { _rules = value; }
        }


        /// <summary>
        /// Gets or sets a value indicating whether the application should save activities state on every change.
        /// </summary>
        /// <value>
        /// Returns <c>true</c> if the application should save activities state on every change; otherwise, <c>false</c>.
        /// </value>
        [XmlAttribute]
        public bool SaveActivitiesStateOnEveryChange { get; set; }


        /// <summary>
        /// Gets or sets the settings.
        /// </summary>
        /// <value>
        /// The settings.
        /// </value>
        public ApplicationSettings Settings
        {
            get { return _settings; }
            set { _settings = value; }
        }

        #endregion

    }
}